#pragma once
#include <vector>
#include "clcommap.h"
#include "clcomfileparser.h"
#include "ParseXMLConfigFile.h"
#include "SelfFormartFile.h"
#include "CADFile.h"

class CFileManageCenter :
    public CLComFileParser
{
private:
	CFileManageCenter();
public:
    virtual ~CFileManageCenter();
public:
    /*begin:xml*/
	int XMLCreateFile(const char* filename, char* czID);
	int XMLOpenFile(const char* fileName, char* czID);

	//int XMLGetNodeByID(XMLFILE inFile, const char* nodeName, char* czID);
	int XMLGetNodeByFile(XMLFILE pFile, const char* nodeName, char* czID);
	int XMLGetNodeByFatherNode(XMLFILE pFile, XMLTREE pFathertree, const char* childNodeName, char* czID);
	int XMLGetNodeValueEx(XMLFILE pFile, const char*  fathernodename, const char*  nodename, XMLNODEINFO& outinfo);
	int XMLSetNodeValueEx(XMLFILE pFile, const char*  fathernodename, const char*  nodename, XMLNODEINFO& outinfo);

    int XMLGetValue(XMLFILE pFile, const char*  aName, XMLNODEINFO& outinfo);
    int XMLSetNodeValue(XMLFILE pFile, const char*  aName, XMLNODEINFO& ininfo);
		int XMLGetNodeInfo(XMLFILE pFile, XMLTREE ptree, XMLNODEINFO& value);
        int XMLSetNodeValueEx(XMLFILE pFile, XMLTREE ptree, XMLNODEINFO& value);
		int XMLDelNode(XMLFILE pFile, XMLTREE ptree);
		int XMLAddNode(XMLFILE pFile, XMLTREE pFathertree, XMLNODEINFO& value);

		int XMLGetFahterNode(XMLFILE pFile, XMLTREE pChildtree, char* czID);
		int XMLGetChildNodes(
			XMLFILE pFile, 
			XMLTREE ptree, 
			vector<string>& list);

		int XMLGetRootNode(XMLFILE pFile, char* czID);

		int XMLSaveXMLFile(XMLFILE pFile);

		void XMLCloseFile(XMLFILE pFile);

		int XMLModifyNodeAttribute(XMLFILE pFile, XMLTREE ptree, const char* attributeName, const char* attributeValue);
	/*end:xml*/

		/*begin:SELF FILE*/
		int SELFFCreateFile(const char* inFilename, char* czID, bool bCreate);
		void SELFFCLOSEFile(const char* fid);
        bool SELFFBFileValid(const char* fid);
		int SELFFReadFile(const char* fid, void* readContent, int contentLen);
		int SELFFReadLine(const char* fid, void* readcontent, int contentLen);
        bool SELFFReadOver(const char* fid);
		int SELFFRWriteFile(const char* fid, void* writeStr, int nWriteSize);
		int SELFFAppendWriteFile(const char* fid, void* writeStr, int nWriteSize);
        void SELFFSetEncrypt(const char* fid, bool bEncrypt);
		void SELFFSetFileName(const char* fid, const char* filename);
		void SELFFGetFileName(const char* fid, char* outfilename, int nBuffersize);
		int SELFFGetFileSize(const char* fid);
		/*begin:SELF FILE*/

		/*begin:cad*/
		int CADCreateFile(const char* inFilename, char* czID);
		int CADOpenFile(const char* inFileName, char* czID);
		int CADGetColumns(const char* fid, CADCOLUMNLINE& outLineColumn);
		int CADGetData(const char* fid, CADCOLUMNLINE& inLineColumn, FM_VALUE_TYPE inType, CADVALUEINFO& outValue);

		int CADAddData(const char* fid, CADCOLUMNLINE& inLineColumn, FM_VALUE_TYPE inType, CADVALUEINFO Value);

		void CADCloseFile(const char* fid);
		int CADSaveFile(const char* fid, const char* filename);
		/*end:cad*/

private:
	FM_CAD_FILE_TYPE ParseCADTypeByName(const char* filename);
public:
	static CFileManageCenter* GetInstance();
	static void Release();
public:
	static CFileManageCenter* _Instance;
public:
    CLComMap<string, string> _mapFileNameFileID;
    CLComMap<string, CParseXMLConfigFile*> _mapIDXMLFiles;
    CLComMap<string, PSELFFORMARTFILE> _mapIDSELFFFiles;
    CLComMap<string, PPARSECADFILE> _mapIDCADFiles;
};

